package com.zhongying.customer;

import com.itextpdf.text.log.SysoCounter;
import com.zhongying.jf.service.SaleLoanQueryService;
import com.zhongying.jf.service.UserQueryService;
import com.zhongying.sys.controller.AbstractController;
import com.zhongying.sys.entity.SysUserEntity;
import com.zhongying.sys.utils.PageUtils;
import com.zhongying.sys.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
//出借
@RequestMapping("/loan")
public class LoanController extends AbstractController {

    public static final Logger logger = LoggerFactory.getLogger(LoanController.class);

    @Autowired
    private SaleLoanQueryService saleQueryService;

  
    /**
     * 出借列表
     */
    @RequestMapping("/listSale")
    @ResponseBody
    public R queryMyList(String startDate, String endDate, String type, String cusId,
                         Integer page, Integer limit, HttpServletRequest httpServletRequest){
        SysUserEntity sysUserEntity = this.getUser();
        Map inMap = new HashMap();
        inMap.put("startDate",startDate == null ? null :startDate.trim());
        inMap.put("endDate",endDate == null ? null :endDate.trim());
        inMap.put("type",type == null ? null :type.trim());
        inMap.put("cusId",cusId == null ? null :cusId.trim());
        inMap.put("offset", (page - 1) * limit);
        inMap.put("limit", limit);
        inMap.put("userId", sysUserEntity.getUserId());
        List<Map> result = saleQueryService.queryLLoanList(inMap);
        int count = saleQueryService.queryLLoanListOne(inMap);

        
        PageUtils pageUtil = new PageUtils(result,count, limit, page);

        System.out.println("pageUtil:"+pageUtil);
        return R.ok().put("page", pageUtil);
    }
    
    /**
     * 出借详情
     */
    @RequestMapping( value ="/listSaleDetails" )
    @ResponseBody
    public R queryMyListDeatils(String startDate, String endDate, String type, String cusId,
            Integer page, Integer limit, HttpServletRequest httpServletRequest){
		SysUserEntity sysUserEntity = this.getUser();
		Map inMap = new HashMap();
		inMap.put("startDate",startDate == null ? null :startDate.trim());
		inMap.put("endDate",endDate == null ? null :endDate.trim());
		inMap.put("type",type == null ? null :type.trim());
		inMap.put("cusId",cusId == null ? null :cusId.trim());
		inMap.put("offset", (page - 1) * limit);
		inMap.put("limit", limit);
		inMap.put("userId", sysUserEntity.getUserId());
		Map result = saleQueryService.queryLLoanListDetails(inMap);
		System.out.println("result:"+result);
		
		PageUtils pageUtil = new PageUtils((List<Map>) result.get("userInfoList"),(Integer) result.get("count") , limit, page);
		
		System.out.println("pageUtil:"+pageUtil);
		return R.ok().put("page", pageUtil);
		}
}
